package com.starry.compose_study.state

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.runtime.Composable
import com.starry.compose_study.state.four.TodoScreen
import com.starry.compose_study.state.four.TodoViewModel
import com.starry.compose_study.ui.theme.Compose_studyTheme

class TodoActivity : ComponentActivity() {

    private val viewModel: TodoViewModel by viewModels()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Compose_studyTheme {
                TodoActivityScreen()
            }
        }
    }

    @Composable
    private fun TodoActivityScreen() {
        TodoScreen(
            items = viewModel.todoItems,
            currentEditing = viewModel.currentEditItem,//正在编辑的条目
            onAddItem = viewModel::addItem,//增加
            onRemoveItem = viewModel::removeItem,//删除
            onStartEdit = viewModel::onEditItemSelected,//开始编辑
            onEditItemChange = viewModel::onEditItemChange,//正在编辑
            onEditDone = viewModel::onEditDone//编辑完成
        )
    }
}